﻿using System;
using System.Collections.Generic;
using System.Text;

using System.IO;

namespace WOWMultiPlay
{
    public static class Helper_Settings
    {
        public static void LoadSettings(string SettingsFilePath)
        {
            if (File.Exists(Setting_Global.SettingsFilePath))
            {
                Helper_FileEncoding.CheckFileEncodingAndChange(SettingsFilePath, Setting_Global.DefaultIniFileEncoding);

                Setting_Global.AppOpacity = Convert.ToDouble(Helper_INIFile.IniReadValue(Setting_Global.IniFileSection_AppSettings, "AppOpacity", SettingsFilePath));
                Setting_Global.ProcessName = Helper_INIFile.IniReadValue(Setting_Global.IniFileSection_AppSettings, "ProcessName", SettingsFilePath);
                Setting_Global.Interval_KeyPress = Helper_INIFile.IniReadValue(Setting_Global.IniFileSection_AppSettings, "Interval_KeyPress", SettingsFilePath);
                Setting_Global.Interval_KeyDown_Up = Helper_INIFile.IniReadValue(Setting_Global.IniFileSection_AppSettings, "Interval_KeyDown_Up", SettingsFilePath);
                Setting_Global.MaxButtonCountPerLine = Convert.ToInt32(Helper_INIFile.IniReadValue(Setting_Global.IniFileSection_AppSettings, "MaxButtonCountPerLine", SettingsFilePath));
                Setting_Global.WindowWidth = Convert.ToInt32(Helper_INIFile.IniReadValue(Setting_Global.IniFileSection_AppSettings, "WindowWidth", SettingsFilePath));
                Setting_Global.WindowHeight = Convert.ToInt32(Helper_INIFile.IniReadValue(Setting_Global.IniFileSection_AppSettings, "WindowHeight", SettingsFilePath));
            }
            else
            {
                CreateDefaultSettings(SettingsFilePath);
                LoadSettings(SettingsFilePath);
            }
        }

        private static void CreateDefaultSettings(string SettingsFilePath)
        {
            Helper_INIFile.CreateINIFile(SettingsFilePath);

            Helper_INIFile.IniWriteValue(Setting_Global.IniFileSection_AppSettings, "AppOpacity", Setting_Global.AppOpacity.ToString(), SettingsFilePath);
            Helper_INIFile.IniWriteValue(Setting_Global.IniFileSection_AppSettings, "ProcessName", Setting_Global.ProcessName, SettingsFilePath);
            Helper_INIFile.IniWriteValue(Setting_Global.IniFileSection_AppSettings, "Interval_KeyPress", Setting_Global.Interval_KeyPress, SettingsFilePath);
            Helper_INIFile.IniWriteValue(Setting_Global.IniFileSection_AppSettings, "Interval_KeyDown_Up", Setting_Global.Interval_KeyDown_Up, SettingsFilePath);
            Helper_INIFile.IniWriteValue(Setting_Global.IniFileSection_AppSettings, "MaxButtonCountPerLine", Setting_Global.MaxButtonCountPerLine.ToString(), SettingsFilePath);
            Helper_INIFile.IniWriteValue(Setting_Global.IniFileSection_AppSettings, "WindowWidth", Setting_Global.WindowWidth.ToString(), SettingsFilePath);
            Helper_INIFile.IniWriteValue(Setting_Global.IniFileSection_AppSettings, "WindowHeight", Setting_Global.WindowHeight.ToString(), SettingsFilePath);
        }

        public static void SaveWindowsSize(string SettingsFilePath)
        {
            Helper_INIFile.IniWriteValue(Setting_Global.IniFileSection_AppSettings, "WindowWidth", Setting_Global.WindowWidth.ToString(), SettingsFilePath);
            Helper_INIFile.IniWriteValue(Setting_Global.IniFileSection_AppSettings, "WindowHeight", Setting_Global.WindowHeight.ToString(), SettingsFilePath);
        }
    }
}